package cn.itsource.base.util;

/**
 * 自定义错误码：统一处理异常响应信息
 */
public enum ErrorCode {
    SYSTEM_ERROR("1001","系统内部异常"), //自定义的错误码尽量往1000以上去写
    SUCCESS("200","操作成功"), //自定义的错误码尽量往1000以上去写
    BUSINESS_DEPT_ERROR("5001","只能从最后一级部门修改"), //自定义的错误码尽量往1000以上去写
    BUSINESS_DEPT2_ERROR("5002","只能从最后二级部门修改"), //自定义的错误码尽量往1000以上去写
    BUSINESS_REGISTER_ERROR("5003","密码不一致"), //自定义的错误码尽量往1000以上去写
    BUSINESS_REGISTER_USERNAME_ERROR("5004","该账号已存在"), //自定义的错误码尽量往1000以上去写
    BUSINESS_REGISTER_SHOP_NAME_ERROR("5005","该店铺已被注册"), //自定义的错误码尽量往1000以上去写
    BUSINESS_IS_SHOP_NAME_ERROR("5006","店铺名不合规"), //自定义的错误码尽量往1000以上去写
    BUSINESS_IS_SHOP_ADDRESS_ERROR("5007","店铺地址不合规"), //自定义的错误码尽量往1000以上去写
    BUSINESS_IS_SHOP_IMG_ERROR("5008","logo不合规"), //自定义的错误码尽量往1000以上去写
    RUNTIME_NULL_ERROR("3001","null异常"), //自定义的错误码尽量往1000以上去写
    RUNTIME_SYSTEM_MALICE_ERROR("5009","您发送的短信已超今日上限"), //自定义的错误码尽量往1000以上去写
    BUSINESS_LOGIN_SYSTEM_ERROR("5010","用户或密码不正确"),
    BUSINESS_ROLE_REPEAT_ERROR("5011","角色编号已存在！"),
    BUSINESS_MENU_SUBORDINATE_ERROR("5012","请先删除下级"),
    ARITHMETIC_ERROR("2001","除数不能为0"); //自定义的错误码尽量往1000以上去写

    //错误码
    private String code;
    //错误信息
    private String message;

    ErrorCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }
    public String getMessage() {
        return message+"["+code+"]";
    }

    public static ErrorCode getErrorCoudeByCode(String code){
        ErrorCode[] values = ErrorCode.values();
        for (ErrorCode value : values) {
            if(value.getCode().equals(code)){
                return value;
            }
        }
        return null;
    }
}